package sample;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import sample.domain.ExpectedNotice;

import java.net.URL;
import java.util.ResourceBundle;

public class AddModifyDialogController implements Initializable {
    private MainController mainController;
    private Stage stage;
    private ExpectedNotice privateNotice;

    public Stage getStage() {
        return stage;
    }

    public void setStage(Stage stage) {
        this.stage = stage;
    }

    public MainController getMainController() {
        return mainController;
    }

    public void setMainController(MainController mainController) {
        this.mainController = mainController;
    }

    public void setNotice(ExpectedNotice notice) {
        addEmailText.setText(notice.getEmail());
        addCompanyText.setText(notice.getCompany());
        addKeyText.setText(notice.getKeyword());

        privateNotice = notice;
    }

    public void onAddConfirmBtnClick() {

        ExpectedNotice notice;
        if (privateNotice == null) {
            notice = new ExpectedNotice();
            notice.setEmail(addEmailText.getText());
            notice.setKeyword(addKeyText.getText());
            notice.setCompany(addCompanyText.getText());

            mainController.addNoticeCallBack(notice);
        } else {
            notice = privateNotice;
            notice.setEmail(addEmailText.getText());
            notice.setKeyword(addKeyText.getText());
            notice.setCompany(addCompanyText.getText());

            mainController.editNoticeCallBack(notice);
        }
        stage.close();
    }

    @FXML
    private TextField addEmailText;
    @FXML
    private TextField addCompanyText;
    @FXML
    private TextField addKeyText;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
    }
}
